﻿using ArtMath.Core.Data;
using ArtMath.Core.Helper;
using System;

namespace ArtMath.PointCollection
{
    [Serializable]
    public class Hyperbola : ConicBase
    {
        public double RealAxisHalfLength, ImaginaryAxisHalfLength;
        public Hyperbola()
        {

        }
        public Hyperbola(PointD center, double rotate, double a, double b) : base(center, rotate)
        {
            RealAxisHalfLength = a;
            ImaginaryAxisHalfLength = b;
        }
        public override bool Contains(PointD pt)
        {
            double c = Math.Sqrt(RealAxisHalfLength * RealAxisHalfLength + ImaginaryAxisHalfLength * ImaginaryAxisHalfLength);
            PointD f1 = Center.Offset(RotateAngle, c), f2 = Center.Offset(RotateAngle + Math.PI, c);
            return Math.Abs(pt.DistanceTo(f1) - pt.DistanceTo(f2)).AlmostEqual(2 * RealAxisHalfLength) && AfterContains(pt);
        }
    }
}
